package com.furns.dao.impl;

import com.furns.dao.BasicDAO;
import com.furns.dao.OrderDAO;
import com.furns.entity.Order;

import java.util.List;

/**
 * @Author LuoJiaCheng
 * @ID 2240129126
 * @Version 1.0
 */
public class OrderDAOImpl extends BasicDAO<Order> implements OrderDAO {
    @Override
    public int saveOrder(Order order) {
        String sql="INSERT INTO `order`(`id`,`create_time`,`price`,`status`,`member_id`)\n" +
                "VALUES(?,?,?,?,?)";
        return update(sql,order.getId(),order.getCreate_time(),order.getPrice(),order.getStatus(),order.getMember_id());
    }

    @Override
    public Order showOrder(String orderId) {
        String sql="select id,create_time,price,`status`,member_id from `order` where id=?";
        Order order = querySingle(sql, Order.class, orderId);
        return order;
    }



    @Override
    public int getTotalRow() {
        String sql="select count(*) from `order`";
        return  ((Number)queryScalar(sql)).intValue();
    }


    @Override
    public List<Order> getPageItems(int begin, int pageSize) {
        String sql ="select id,create_time,price,`status`,member_id from `order` limit ?,?";
        return queryMulti(sql,Order.class,begin,pageSize);
    }

    @Override
    public int getTotalRow(int memberId) {
        String sql="select count(*) from `order` where member_id=?";
        return  ((Number)queryScalar(sql,memberId)).intValue();
    }
    @Override
    public List<Order> getPageItems(int memberId, int begin, int pageSize) {
        String sql ="select id,create_time,price,`status`,member_id from `order` where member_id=? limit ?,?";
        return queryMulti(sql,Order.class,memberId,begin,pageSize);
    }
}
